#pragma once

enum
{
	MSGTYPE_ROUTE_SEL = 0,
	MSGTYPE_ROUTE_REPLY,
	MSGTYPE_USER_REG,
	MSGTYPE_USER_AUTH,
	MSGTYPE_AIRLINE_AUTH,
	MSGTYPE_AIRLINE_ADDROUTE,
	MSGTYPE_SUCCESS_REPLY,
	MSGTYPE_CUST_RESERV,
	MSGTYPE_VIEW_ORDER_REQUEST,
	MSGTYPE_VIEW_ORDER_CONTENT,
	MSGTYPE_CANCEL_ORDER,
	MSGTYPE_VIEW_ROUTES,
};

struct MSG_BASE 
{
	int nMsgLen;
	int nMsgType;
};

struct ROUT_ENTRY
{
	int id;
	char strFlightID[50];
	char strAirLine[100];
	char strStartAddr[100];
	char strDestination[100];
	char depTime[30]; //like '2012-05-02 21:23'
	char arvTime[30];
	int nBusiness;
	int nFirstClass;
	int nEconomy;
};

struct MSG_ROUTE_REPLY : public MSG_BASE
{
	int nEntryNum;
	ROUT_ENTRY entries[1];

	void Initialize(int nSize, int nNum) 
	{
		if (nSize <= 0 || nNum < 0)
		{
			nMsgType = MSGTYPE_ROUTE_REPLY;
			nMsgLen = 0;
			return;
		}

		nMsgLen = nSize;
		nMsgType = MSGTYPE_ROUTE_REPLY;
		nEntryNum = nNum;
	}

	static int CalculateMsgSize(int nNum) 
	{ return sizeof(MSG_ROUTE_REPLY) + sizeof(ROUT_ENTRY) * (nNum - 1); }
};

enum CABIN_TYPE
{
	CABINE_BUSINESS = 1,
	CABINE_FIRSTCLASS = 2,
	CABINE_ECONOMY = 3,
};

struct MSG_ROUTE_SEL : public MSG_BASE
{
	char strStartAddr[100];
	char strDestination[100];
	char depTimeBeg[30];//like '2012-05-02 21:23'
	char depTimeEnd[30];
	CABIN_TYPE nCabinType;

	MSG_ROUTE_SEL() 
	{
		nCabinType = CABINE_ECONOMY;
		nMsgLen = sizeof(MSG_ROUTE_SEL);
		nMsgType = MSGTYPE_ROUTE_SEL;
	}
};

struct MSG_USER_REG : public MSG_BASE
{
	char szAccount[50];
	char szPasswd[50];

	MSG_USER_REG() 
	{
		nMsgLen = sizeof(MSG_USER_REG);
		nMsgType = MSGTYPE_USER_REG;
	}
};

struct MSG_USER_AUTH : public MSG_BASE
{
	char szAccount[50];
	char szPasswd[50];

	MSG_USER_AUTH() 
	{
		nMsgLen = sizeof(MSG_USER_AUTH);
		nMsgType = MSGTYPE_USER_AUTH;
	}
};

struct MSG_AIRLINE_AUTH : public MSG_BASE
{
	char szAccount[50];
	char szPasswd[50];

	MSG_AIRLINE_AUTH() 
	{
		nMsgLen = sizeof(MSG_AIRLINE_AUTH);
		nMsgType = MSGTYPE_AIRLINE_AUTH;
	}
};

struct MSG_SUCCESS_REPLY : public MSG_BASE
{
	bool bSuccess;
	char szReason[1024];

	MSG_SUCCESS_REPLY() 
	{
		nMsgLen = sizeof(MSG_SUCCESS_REPLY);
		nMsgType = MSGTYPE_SUCCESS_REPLY;
	}
};

struct MSG_CUST_RESERV : public MSG_BASE
{
	int nRouteNum;
	CABIN_TYPE nCabTp;

	MSG_CUST_RESERV() 
	{
		nCabTp = CABINE_BUSINESS;
		nMsgLen = sizeof(MSG_CUST_RESERV);
		nMsgType = MSGTYPE_CUST_RESERV;
	}
};

struct MSG_VIEW_ORDER_REQUEST : public MSG_BASE
{
	MSG_VIEW_ORDER_REQUEST() 
	{
		nMsgLen = sizeof(MSG_VIEW_ORDER_REQUEST);
		nMsgType = MSGTYPE_VIEW_ORDER_REQUEST;
	}
};

struct MSG_CANCEL_ORDER : public MSG_BASE
{
	int nReservId;

	MSG_CANCEL_ORDER() 
	{
		nMsgLen = sizeof(MSG_CANCEL_ORDER);
		nMsgType = MSGTYPE_CANCEL_ORDER;
	}
};

struct ORDER_ENTRY
{
	int id;
	char strFlightID[50];
	char strAirLine[100];
	char strStartAddr[100];
	char strDestination[100];
	char depTime[30]; //like '2012-05-02 21:23'
	char arvTime[30];
	CABIN_TYPE nCabinType;
};

struct MSG_VIEW_ORDER_CONTENT : public MSG_BASE
{
	int nEntryNum;
	ORDER_ENTRY orders[1];

	static int CalculateMsgSize(int nNum) 
	{ return sizeof(MSG_VIEW_ORDER_CONTENT) + sizeof(ORDER_ENTRY) * (nNum - 1); }

	void Initialize(int nSize, int nNum) 
	{
		nMsgLen = nSize;
		nMsgType = MSGTYPE_VIEW_ORDER_CONTENT;
		nEntryNum = nNum;
	}
};

struct MSG_AIRLINE_ADDROUTE : public MSG_BASE
{
	ROUT_ENTRY entry;

	MSG_AIRLINE_ADDROUTE()
	{
		nMsgLen = sizeof(MSG_AIRLINE_ADDROUTE);
		nMsgType = MSGTYPE_AIRLINE_ADDROUTE;
	}
};

struct MSG_VIEW_ROUTES : public MSG_BASE
{
	MSG_VIEW_ROUTES()
	{
		nMsgLen = sizeof(MSG_VIEW_ROUTES);
		nMsgType = MSGTYPE_VIEW_ROUTES;
	}
};